package com.ys.web.user.risk;

import cn.hutool.core.util.ObjectUtil;
import com.ys.utils.base.http.ResponseHandler;
import com.ys.utils.base.j2se.StringHandler;
import com.ys.utils.spring.config.SystemError;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("manager/user/risk/")
public class RiskController {
    @Autowired
    private RiskService riskService;

    //风控用户列表接口
    @PostMapping("list")
    public String getRiskList(RiskVo riskVo) {
        Map<String, Object> result = new HashMap<>();
        List<RiskListInfo> list = riskService.getRiskListInfo(riskVo);
        if (!list.isEmpty()) {
//            Set<String> ids = list.stream().map(RiskListInfo::getId).collect(Collectors.toSet());
//            List<BusiUser> userInfoList = riskService.getMiningUserInfoByIds(ids);
//            Map<String, BusiUser> collect = userInfoList.stream().collect(Collectors.toMap(x -> StringHandler.getString(x.getSysId()), Function.identity()));
//            List<RiskListInfo> resultListInfo = list.stream().peek(x -> x.setRealName(collect.get(x.getId()).getAppUserName())).collect(Collectors.toList());
//            if (StringHandler.isEmpty(riskVo.getRealName())) {
//                result.put("list", resultListInfo);
//            } else {
//                List<RiskListInfo> resultListInfo2 = resultListInfo.stream().filter(x -> x.getUserName().contains(riskVo.getRealName()) || x.getRealName().contains(riskVo.getRealName())).collect(Collectors.toList());
//            }
            result.put("list", list);
            int count = riskService.getRiskListCount(riskVo);
            result.put("dataSum", count);
        } else {
            result.put("dataSum", 0);
            result.put("list", new ArrayList<>());
        }
        return ResponseHandler.success(result);
    }

    //解除账号风控
    @PostMapping("unrisk")
    public String unrisk(String id) {
        if (StringHandler.isEmpty(id)) {
            SystemError.wrapBs("500", "参数传递错误");
        }
        riskService.updateRisk(new Risk(StringHandler.getLong(id), "后台解除风控"));
        return ResponseHandler.success();
    }
}
